<!--
* @Author: zhuxiaolong fengshangxin@yunjinhz.com
* @Date:  2023-05-09 14:12:03
 * @FilePath: \zmglpt-ui-mobile\src\pages\check\approve\declarePartakeOrg.vue
* @Description: 市管-专项行动奖励审批跳转页
-->

<template>
  <view class="page">
    <!-- #ifndef H5-DINGDING -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999"></theme-navbar>
    <!-- #endif -->
    <view></view>
    <view class="content" v-if="showArea">
      <u-form ref="uForm" v-model="formData" label-position="top" label-width="auto">
        <form-section title="基础信息"></form-section>
        <u-form-item label="行动名称">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.actionName"></u-input>
        </u-form-item>
        <u-form-item label="行动起止日期">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.startEndDate"></u-input>
        </u-form-item>
        <u-form-item label="发起单位">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.orgName"></u-input>
        </u-form-item>
        <u-form-item label="参与单位">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.partakeOrgNames"></u-input>
        </u-form-item>
        <u-form-item label="参与单位数量">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.partakeOrgNum"></u-input>
        </u-form-item>
        <u-form-item label="行业外参与单位">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.outsideOrg"></u-input>
        </u-form-item>
        <u-form-item label="奖励发放单位">
          <u-input placeHolder="" type="text" :disabled="true" v-model="orgName"></u-input>
        </u-form-item>
        <u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()" :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        <form-section title="奖励申报"></form-section>
        <!-- 提交表单 start -->
        <u-form-item label="奖金合计(万元)" :required="true" prop="applyReason">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.bonusTotal"></u-input>
        </u-form-item>
        <u-form-item label="奖励人数">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.rewardPersonNum"></u-input>
        </u-form-item>
        <u-form-item label="承办人">
          <u-input placeHolder="" type="text" :disabled="true" v-model="formData.handlePerson"></u-input>
        </u-form-item>
        <u-form-item label="行动内容">
          <u-input placeHolder="" type="textarea" :disabled="true" v-model="formData.actionContent"></u-input>
        </u-form-item>
        <u-form-item label="奖励依据">
          <u-input placeHolder="" type="textarea" :disabled="true" v-model="formData.rewardBasis"></u-input>
        </u-form-item>
        <u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()" :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        <form-section title="附件信息"></form-section>
        <scroll-view :scroll-y="true" :scroll-x="true" :style="{ marginTop: '5px',}">
          <u-tr>
            <u-th width="60%">材料类别</u-th>
            <u-th width="40%">操作</u-th> 
          </u-tr>
          <u-tr v-for="(it,index) in dataSource" :key="index" style="margin:10px 0">
            <u-td width="60%">{{ it.archiveName }}</u-td>
            <u-td width="40%" style="color:#0070D2">{{ it.archiveList[0].fileName }}</u-td>
          </u-tr>
        </scroll-view>
        <!-- 提交表单 end -->
        <u-gap v-if="!approvalDisabled && !ifSub" :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()" :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        <form-section v-if="!approvalDisabled && !ifSub" title="审批信息"></form-section>
        <u-form-item v-if="!approvalDisabled && !ifSub" label="审批意见">
          <u-input type="textarea" height="100" :auto-height="true" placeholder="请输入" v-model="approveMemo" />
        </u-form-item>
        <u-gap :marginRight="getGapMarginRowNumber()" :marginLeft="getGapMarginRowNumber()" :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        <form-section title="审批历史"></form-section>
        <u-form-item label="" class="u-m-l-12">
          <flow-his-no-doc :bizUuid="prvParam.bizUuid" processDefKey="declarePartakeOrg" :endTitle="endTitle"></flow-his-no-doc>
        </u-form-item>
      </u-form>
    </view>
    <!-- <view class="submit-btns btn-other-cls" v-if="ifSub">
            <u-button class="u-btn" type="primary" @click="validateStopForm">提交</u-button>
        </view> -->
    <view class="submit-btns btn-other-cls" v-if="!approvalDisabled && !ifSub && !approveDis">
      <u-button class="u-btn" type="error" @click="unSubmit">退回</u-button>
      <u-button class="u-btn" type="primary" @click="submit">审批通过</u-button>
    </view>
    <!-- 下拉选择用 -->
    <dic-choice :keyWord="dicKeyWords" :currentSelect="dicCurrentSelect" v-model="dicShow" @confirm="selectDicConfirm"></dic-choice>
  </view>
</template>

<script>
import DicChoice from '@/components/dic_choice.vue';
import DicInput from '@/components/dic_input.vue';
import formSection from '@/components/form-section.vue';
import checkService from '@/service/check/check.service.js';
import {getSpecialDeclare, getSpecialAction ,specialArchive} from '@/service/check/check.service.js';
// import commonService from '@/service/common/common.service.js';
// import { M_DAY_PLAN_STATUS } from '@/service/check/mapping/enum.js';
import FlowHisNoDoc from '@/components/flow-his-no-doc.vue';
export default {
  components: {
    formSection,
    FlowHisNoDoc,
    DicChoice,
    // DicInput,
  },
  onLoad() {
    this.prvParam = this.getRouteParam() || {};
    this.initData1();
  },
  onReady() {
    // this.$refs.uForm.setRules(this.rules);
  },
  data() {
    return {
      dicKeyWords: '',
      dicCurrentSelect: '',
      dicShow: false,
      dicType: '',
      showArea:true,
      prvParam: {},
      formData: {
      },
      orgName:'本单位',
      actionUuid: '',
      dataSource: [],
      scrollRealHeight: '50px',
      bean: {},
      approvalDisabled: false,
      approveMemo: '同意',
      noCheckPersonNodes: '03',
      approvePersonUuid: '',
      rightIconStyle: {
        fontSize: '40rpx',
      },
      ifSub: false,
      approveDis: true,
      endTitle: '',
    };
  },
  methods: {
    getCurrStatus() {
      checkService
        .getFlowNodeStep({ bizUuid: this.prvParam.bizUuid, processDefKey: 'declarePartakeOrg' })
        .then(res => {
          if (res.bean) {
            let step;
            if (res.bean) {
              step = res.bean.step;
            }
            this.approveDis = false;
            if (step == 'view') {
              this.approvalDisabled = true;
            } else if (step == 'approveDis') {
              this.ifSub = true;
            }
          } else {
            console.log(res.msg);
          }
        });
    },
    initData1() {
      this.approvePersonUuid = this.$store.state.userInfo.user.personUuid;
      this.$modal.showLoading('加载中...');
      checkService
        .getSpecialDeclare(this.prvParam.bizUuid, '')
        .then(res => {
          if (res.bean) {
            // this.bean = res.bean;
            this.showArea = false;
            this.$modal.hideLoading();
            // this.endTitle = this.bean.status == M_DAY_PLAN_STATUS.TERMINATION ? '结束' : '...';
            this.formData.bonusTotal = res.bean.bonusTotal;
            this.formData.rewardPersonNum = res.bean.rewardPersonNum;
            this.formData.handlePerson = res.bean.handlePerson;
            this.formData.actionContent = res.bean.actionContent;
            this.formData.rewardBasis = res.bean.rewardBasis;
            this.actionUuid = res.bean.actionUuid;
            if(this.actionUuid) {
              this.initData2(this.actionUuid) 
              this.initData3(this.actionUuid) 
              this.getCurrStatus();
              this.showArea = true;
            }
          } else {
            this.$modal.alert(res.msg, () => {
              this.error();
            });
          }
        })
        .catch((e) => {
          this.$modal.hideLoading();
          this.$modal.alert('加载失败' + e, () => {
            this.error();
          });
        });
    },
    initData2(actionUuid) {
      checkService.getSpecialAction(actionUuid, '')
        .then(res => {
          if (res.bean) {
            this.endTitle = res.bean.status == "05" ? '结束' : '...';
            this.showArea = false;
            this.$modal.hideLoading();
            this.formData.actionName = res.bean.actionName;
            this.formData.startEndDate = res.bean.startDate + '至' + res.bean.endDate;
            this.formData.orgName = res.bean.orgName;
            this.formData.partakeOrgNames = res.bean.partakeOrgNames;
            this.formData.partakeOrgNum = res.bean.partakeOrgNum;
            this.formData.outsideOrg = res.bean.outsideOrg;    
            this.showArea = true;
          }
        })
        .catch(e => {
          this.$modal.hideLoading();
          this.$modal.alert('加载失败' + e, () => {
            this.error();
          });
        });
    },
    initData3(actionUuid) {
      checkService.specialArchive(actionUuid, '')
        .then(res => {
          this.$modal.hideLoading();
          if (res.data.length) {
            this.dataSource = res.data;
          }
        })
        .catch(e => {
          this.$modal.hideLoading();
          this.$modal.alert('加载失败' + e, () => {
            this.error();
          });
        });
    },
    toSelectPerson() {        
      this.$u.route({       
        url: '/pages/commonPage/flowUserSelectComponent',
        params: {
          flowFormCode: 'declarePartakeOrg', // 日计划终止的gfcode
          docInsUuid: this.prvParam.bizUuid,
        },
      });
    },
    getGapMarginRowNumber() {
      return '-' + this.$theme.cm_content_paddng_row.replace('rpx', '');
    },
    updateBackState(param) {
      if (param.flowUserSelectBack) {
        // 选择审批人
        let nextPersons = [];
        for (let fu of param.flowUserSelectBack) {
          nextPersons.push(fu.personId);
        }
        if (this.ifSub) {
          this.stopPlan(nextPersons.join(','));
        } else {
          this.realSubmit(nextPersons.join(','));
        }
      }
    },
    selectDicConfirm(e) {
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.M_DAY_PLAN_TERMINATION_REASON) {
        this.formData.applyReasonName = e[0].label;
        this.formData.applyReason = e[0].extra.bcbCode;
      }
    },
    validateStopForm() {
      this.$refs.uForm.validate((valid) => {
        if (valid) {
          this.toSelectPerson();
        }
      });
    },
    stopPlan(persons) {
      if (!persons) {
        this.$u.toast('请选择人员！');
        return;
      }
      let parms = {
        bizUuid: this.prvParam.bizUuid,
        nextPersonUuids: persons,
        processDefKey: this.processDefKey,
        busUuid: this.prvParam.bizUuid,
        terminateReasonName: '',
        terminateRemark: '',
        applyReason: this.formData.applyReason,
        applyReasonName: this.formData.applyReasonName,
        remark: this.formData.remark,
      };
      this.$modal.showLoading('正在提交...');
      checkService
        .updateDayPlanToTerminte(parms)
        .then((res) => {
          this.$modal.hideLoading();
          if (res.success) {
            this.backPrev({ paramKey: 'refresh', param: true });
          } else {
            this.$u.toast(res.msg);
          }
        })
        .catch((e) => {
          this.$modal.hideLoading();
          this.$u.toast(res.msg);
        });
    },
    submit() {
      if (this.$u.test.isEmpty(this.approveMemo) || this.approveMemo == '不同意') {
        this.approveMemo = '同意';
      }
      this.$modal.showLoading('请稍后...');
      checkService
        .getFlowIsFinish({
          bizUuid: this.prvParam.bizUuid,
          noCheckPersonNodes: this.noCheckPersonNodes,
        })
        .then((res) => {
          this.$modal.hideLoading();
          if (res.success) {
            if (!res.bean) {
            // 是否流程最后一步
              this.toSelectPerson();
            } else {
              this.realSubmit();
            }
          } else {
            this.$u.toast(res.msg);
          }
        })
        .catch((e) => {
          this.$modal.hideLoading();
          this.$u.toast('请求失败' + e);
        });
    },

    realSubmit(persons) {
      this.$modal.showLoading('正在提交...');
      let parms = {
        bizUuid: this.prvParam.bizUuid,
        nextPersonUuids: persons || '',
        approveMemo: this.approveMemo,
        approveResult: '01', // 同意
        processDefKey: this.prvParam.gfCode,
        approvePersonUuid: this.approvePersonUuid,        
      };
      checkService
        .auditSpecialDeclare(parms)
        .then((res) => {
          this.$modal.hideLoading();
          if (res.success) {
            this.backPrev({ paramKey: 'refresh', param: true });
          } else {
            this.$u.toast('终止审批失败！');
          }
        })
        .catch((err) => {
          this.$modal.hideLoading();
          this.$u.toast('提交异常' + err);
        });
    },
    // 不同意
    unSubmit() {
      if (this.$u.test.isEmpty(this.approveMemo) || this.approveMemo == '同意') {
        this.approveMemo = '不同意';
      }
      let parms = {
        bizUuid: this.prvParam.bizUuid,
        nextPersonUuids: '',
        approveMemo: this.approveMemo,
        approveResult: '03', // 退回
        processDefKey: this.prvParam.gfCode,
        approvePersonUuid: this.approvePersonUuid,
      };
      this.$modal.showLoading('请稍后...');
      checkService
        .auditSpecialDeclare(parms)
        .then((res) => {
          this.$modal.hideLoading();
          if (res.success) {
            this.backPrev({ paramKey: 'refresh', param: true });
          } else {
            this.$u.toast(res.msg);
          }
        })
        .catch((e) => {
          this.$modal.hideLoading();
          this.$u.toast('提交失败' + e);
        });
    },
    error() {
      uni.navigateBack();
    },
    downLoad(){
      console.log('///');
    },
  },
};
</script>

<style scoped lang="scss">
.page {
    padding: 0;
}

.sub-title {
    background: #f5f5f5;
    color: #989ea1;
    font-size: 24rpx;
    border-radius: 4px;
    margin-right: 10px;
    padding: 4px 8px;
}

.f-ctn {
    width: 100%;
}

.tb-lay {
    width: 900px;
    margin-left: 1px;
    margin-right: 1px;
}

.content {
    padding-left: $cm-content-paddng-row;
    padding-right: $cm-content-paddng-row;
    padding-top: $cm-conent-padding-column;
    padding-bottom: 70px;
}

/deep/.u-td {
    height: auto;
}
</style>
            